import os

__cfg = {
        'title':        'phBook',
        'version':      '1.0',
        'copyright':    '2007 (c) by Giuliani Vito, Ivan',
        'bookpath':     '',
        }

def get_config(conf_name):
    '''Return a config value'''
    try:
        return __cfg[conf_name];
    except:
        return None

def set_config(conf_name, conf_value):
    '''Set a config value'''
    __cfg[conf_name] = conf_value


def set_bookpath():
    '''
    Look for .book.csv file in default locations, otherwise create an
    empty one
    '''
    if os.path.exists(os.path.join(os.path.expanduser("~"), ".book.csv")):
        set_config('bookpath', os.path.join(os.path.expanduser("~"), ".book.csv"))
    elif os.path.exists(os.path.join(os.getcwd(), ".book.csv")):
        set_config('bookpath', os.path.join(os.getcwd(), ".book.csv"))
    else:
        '''the .book.csv doesn't exist, create an empty one under home dir'''
        set_config('bookpath', os.path.join(os.path.expanduser("~"), ".book.csv"))
        f = open(get_config('bookpath'), 'wb')
        f.close()
